package com.mdp.sys.ctrl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mdp.core.entity.Result;
import com.mdp.core.err.BizException;
import com.mdp.core.query.QueryTools;
import com.mdp.sys.entity.UserJoinRequire;
import com.mdp.sys.service.UserJoinRequireService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * url编制采用rest风格,如对sys_user_join_require 企业入驻审核流程的操作有增删改查,对应的url分别为:<br>
 *  新增: sys/userJoinRequire/add <br>
 *  查询: sys/userJoinRequire/list<br>
 *  模糊查询: sys/userJoinRequire/listKey<br>
 *  修改: sys/userJoinRequire/edit <br>
 *  删除: sys/userJoinRequire/del<br>
 *  批量删除: sys/userJoinRequire/batchDel<br>
 * 组织 com  顶级模块 mdp 大模块 sys 小模块 <br>
 * 实体 UserJoinRequire 表 sys_user_join_require 当前主键(包括多主键): id; 
 ***/
@RestController("mdp.sys.userJoinRequireController")
@RequestMapping(value="/**/sys/userJoinRequire")
@Api(tags={"企业入驻审核流程操作接口"})
public class UserJoinRequireController {
	
	static Logger logger =LoggerFactory.getLogger(UserJoinRequireController.class);



	@Autowired
	private UserJoinRequireService userJoinRequireService;
 
	
	@ApiOperation( value = "查询企业入驻审核流程信息列表",notes=" ") 
	@ApiResponses({
		@ApiResponse(code = 200,response=UserJoinRequire.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'错误码'},total:总记录数,data:[数据对象1,数据对象2,...]}")
	})
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public Result listUserJoinRequire( @ApiIgnore @RequestParam Map<String,Object>  params){
		
		
		
		IPage page=QueryTools.initPage(params);
		QueryWrapper<UserJoinRequire> qw= QueryTools.initQueryWrapper(UserJoinRequire.class,params);
		List<Map<String,Object>>	userJoinRequireList = userJoinRequireService.selectListMapByWhere(page,qw,params);
		
		return Result.ok().setData(userJoinRequireList);

	}




	@ApiOperation( value = "新增一条企业入驻审核流程信息",notes=" ")
	@ApiResponses({
			@ApiResponse(code = 200,response=UserJoinRequire.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}")
	})
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public Result addUserJoinRequire(@RequestBody UserJoinRequire userJoinRequire) {
		
		
		try{
			if(StringUtils.isEmpty(userJoinRequire.getId())) {
				userJoinRequire.setId(userJoinRequireService.createKey("id"));
			}
			UserJoinRequire userJoinRequireQuery = new  UserJoinRequire();
			userJoinRequireQuery.setJoinBranchId(userJoinRequire.getJoinBranchId());
			userJoinRequireQuery.setJoinUserid(userJoinRequire.getJoinUserid());
			if(userJoinRequireService.countByWhere(userJoinRequireQuery)>0){
				return Result.error("您已申请过，请耐心等待，或者联系管理员");
			}
			userJoinRequire.setAgree("0");
			userJoinRequire.setJoinStatus("0");
			userJoinRequire.setCreateDate(new Date());
			userJoinRequireService.insert(userJoinRequire); 
			return Result.ok().setData(userJoinRequire).setTips("request-success-please-wait","申请提交成功，请耐心等待");
		}catch (BizException e) {
			logger.error("",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("",e);
			return Result.error(e);
		}
	}
	
	/**
	@ApiOperation( value = "删除一条企业入驻审核流程信息",notes=" ")
	@ApiResponses({
		@ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}}")
	}) 
	@RequestMapping(value="/del",method=RequestMethod.POST)
	public Result delUserJoinRequire(@RequestBody UserJoinRequire userJoinRequire){
		
		
		try{
            if(!StringUtils.hasText(userJoinRequire.getId())) {
                 return Result.error("pk-not-exists","请上送主键参数id");
            }
            UserJoinRequire userJoinRequireDb = userJoinRequireService.selectOneObject(userJoinRequire);
            if( userJoinRequireDb == null ){
                return Result.error("data-not-exists","数据不存在，无法删除");
            }
			userJoinRequireService.deleteByPk(userJoinRequire);
		}catch (BizException e) { 
			logger.error("",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("",e);
			return Result.error(e);
		}  
	}
	 */
	
	/**
	@ApiOperation( value = "根据主键修改一条企业入驻审核流程信息",notes=" ")
	@ApiResponses({
		@ApiResponse(code = 200,response=UserJoinRequire.class, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}")
	}) 
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public Result editUserJoinRequire(@RequestBody UserJoinRequire userJoinRequire) {
		
		
		try{
            if(!StringUtils.hasText(userJoinRequire.getId())) {
                 return Result.error("pk-not-exists","请上送主键参数id");
            }
            UserJoinRequire userJoinRequireDb = userJoinRequireService.selectOneObject(userJoinRequire);
            if( userJoinRequireDb == null ){
                return Result.error("data-not-exists","数据不存在，无法修改");
            }
			userJoinRequireService.updateSomeFieldByPk(userJoinRequire);
			return Result.ok().setData(userJoinRequire);
		}catch (BizException e) { 
			logger.error("",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("",e);
			return Result.error(e);
		}  
	}
	*/
	

	
	/**
	@ApiOperation( value = "根据主键列表批量删除企业入驻审核流程信息",notes=" ")
	@ApiResponses({
		@ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}")
	}) 
	@RequestMapping(value="/batchDel",method=RequestMethod.POST)
	public Result batchDelUserJoinRequire(@RequestBody List<UserJoinRequire> userJoinRequires) {
		
		 
		try{ 
			userJoinRequireService.batchDelete(userJoinRequires);
		}catch (BizException e) { 
			logger.error("",e);
			return Result.error(e);
		}catch (Exception e) {
			logger.error("",e);
			return Result.error(e);
		}  
	} 
	*/
}
